# -*- encoding:utf-8  -*-
import socket
import re
import time

if __name__ == '__main__':
    host = "127.0.0.1"
    port = 12000
    server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    address = (host, port)
    server.bind(address)
    while True:
        cont, addr = server.recvfrom(4096)
        print "recieve:" + cont + " from:" + str(addr[0]) + ":" + str(addr[1])
        time.sleep(3)
        if re.search(".*who.*are.*you.*", cont):
            server.sendto("i am udp server", addr)
        elif re.search(".*how.*are.*you.*", cont):
            server.sendto("i am fine thank you", addr)
        else:
            server.sendto("你说啥嘞", addr)
